﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminDefault.Master"
  AutoEventWireup="true" CodeBehind="CustomerContactDetail.aspx.cs" Inherits="ITViet.Web.Admin.CustomerContactDetail" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dxuc" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<%@ Register Assembly="DevExpress.Web.ASPxHtmlEditor.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxHtmlEditor" TagPrefix="dxhe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxTabControl" TagPrefix="dxtc" %>
<%@ Register Assembly="DevExpress.Web.ASPxSpellChecker.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxSpellChecker" TagPrefix="dxwsc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <link rel="Stylesheet" type="text/css" href="/css/swfUpload.css" />

  <script type="text/javascript" src="/Scripts/swfupload.js"></script>

  <script type="text/javascript" src="/Scripts/swfupload.queue.js"></script>

  <script type="text/javascript" src="/Scripts/fileprogress.js"></script>

  <script type="text/javascript" src="/Scripts/handlers.js"></script>

  <script type="text/javascript">
    var uploader;
    var completeFunction = '<%=UploadCompleteFunction %>';
    var uploadSessionName = '<%=UploadSessionName %>';
    var uploadFolder = '<%=UploadFolder%>';
    window.onload = function() {
      uploader = new SWFUpload({
        // Backend Settings
        upload_url: "UploadPage.aspx",
        post_params: {
          "ASPSESSID": "<%=Session.SessionID %>"
        },

        // File Upload Settings
        file_size_limit: "10 MB",
        file_types: "*.*",
        file_types_description: "",
        file_upload_limit: 0,    // Zero means unlimited
        file_queue_limit: 0,
        file_post_name: uploadSessionName,

        // Event Handler Settings - these functions as defined in Handlers.js
        //  The handlers are not part of SWFUpload but are part of my website and control how
        //  my website reacts to the SWFUpload events.
        swfupload_preload_handler: preLoad,
        swfupload_load_failed_handler: loadFailed,
        file_queue_error_handler: fileQueueError,
        file_dialog_complete_handler: fileDialogComplete,
        upload_start_handler: uploadStart,
        upload_progress_handler: uploadProgress,
        upload_error_handler: uploadError,
        upload_success_handler: uploadSuccess,
        upload_complete_handler: uploadComplete,

        // Button settings
        button_image_url: "",
        button_placeholder_id: "spanButtonPlaceholder",
        button_width: 90,
        button_height: 22,
        button_text: '<span class="button"><%=(string)GetGlobalResourceObject("Strings","AttachAFile") %></span>',
        button_text_style: '.button { font-family: Tahoma; font-size: 12pt;text-decoration:underline;color:#60A4A8;}',
        button_text_top_padding: 1,
        button_text_left_padding: 2,
        button_cursor: SWFUpload.CURSOR.HAND,

        // Flash Settings
        flash_url: "../css/swf/swfupload.swf", // Relative to this file
        flash9_url: "../css/swf/swfupload_fp9.swf", // Relative to this file

        custom_settings: {
          finishedUpload: completeFunction
        },

        // Debug Settings
        debug: false
      });
    }
  </script>

  <div id="OpinionContent" style="padding-top: 10px;" class="OpinionContent">
    <dxe:ASPxLabel ID="lblOpinionContent" runat="server" Text="">
    </dxe:ASPxLabel>
  </div>
  <div style="padding-top: 10px;">
  </div>
  <div id="frmCompose" style="padding-top: 10px;">
    <table class="CommonFont" width="100%">
      <tr>
        <td style="width: 70px;">
          <asp:Label ID="Label1" runat="server" Text="<%$ Resources:Strings, To %>" Font-Bold="True"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxTextBox ID="txtTo" ClientInstanceName="txtTo" runat="server" Width="100%">
            <ValidationSettings>
              <ErrorImage Height="14px" />
              <ErrorFrameStyle ImageSpacing="4px">
                <ErrorTextPaddings PaddingLeft="4px" />
              </ErrorFrameStyle>
            </ValidationSettings>
          </dxe:ASPxTextBox>
        </td>
      </tr>
      <tr>
        <td>
          <asp:Label ID="Label4" runat="server" Text="<%$ Resources:Strings, Subject %>" Font-Bold="True"></asp:Label>
          :
        </td>
        <td>
          <dxe:ASPxTextBox ID="txtSubject" ClientInstanceName="txtSubject" runat="server" Width="100%">
            <ValidationSettings>
              <ErrorImage Height="14px" />
              <ErrorFrameStyle ImageSpacing="4px">
                <ErrorTextPaddings PaddingLeft="4px" />
              </ErrorFrameStyle>
            </ValidationSettings>
          </dxe:ASPxTextBox>
        </td>
      </tr>
      <tr>
        <td>
        </td>
        <td style="padding-top: 4px;">
          <div style="float: left">
            <asp:Image ID="Image1" ImageUrl="~/Images/attachment.png" runat="server" />
          </div>
          <div>
            <div id="content" style="float: left; padding-left: 0px;">
              <div id="swfu_container" style="margin: 0px 10px;">
                <span id="spanButtonPlaceholder" style="cursor: pointer;"></span>
              </div>
            </div>
            <div style="padding-left: 20px;">
              <dxwgv:ASPxGridView ID="gvFile" runat="server" AutoGenerateColumns="False" ClientInstanceName="gvFile"
                KeyFieldName="FilePath" OnCustomCallback="gvFile_CustomCallback" OnRowDeleting="gvFile_RowDeleting"
                ClientVisible="False" Border-BorderStyle="Solid" Width="520px">
                <Images>
                  <CollapsedButton Height="12px" Width="11px" />
                  <DetailCollapsedButton Height="9px" Width="9px" />
                  <HeaderFilter Height="18px" Width="18px" />
                  <HeaderActiveFilter Height="18px" Width="18px" />
                  <FilterRowButton Height="13px" Width="13px" />
                  <CustomizationWindowClose Height="17px" Width="17px" />
                  <PopupEditFormWindowClose Height="17px" Width="17px" />
                  <FilterBuilderClose Height="17px" Width="17px" />
                </Images>
                <Border BorderStyle="Solid"></Border>
                <ClientSideEvents EndCallback="function(s,e){ongvFile_EndCallback(s,e);}"></ClientSideEvents>
                <Columns>
                  <dxwgv:GridViewDataTextColumn FieldName="FileName" VisibleIndex="1">
                  </dxwgv:GridViewDataTextColumn>
                  <dxwgv:GridViewCommandColumn ButtonType="Image" VisibleIndex="0" Width="20px">
                    <DeleteButton Visible="True">
                      <Image Url="~/Images/delete.png"></Image>
                    </DeleteButton>
                    <CellStyle Cursor="pointer">
                      <Paddings PaddingLeft="3px"></Paddings>
                    </CellStyle>
                  </dxwgv:GridViewCommandColumn>
                  <dxwgv:GridViewDataTextColumn FieldName="FilePath" Visible="False" VisibleIndex="2">
                  </dxwgv:GridViewDataTextColumn>
                </Columns>
                <Settings ShowColumnHeaders="False" />
                <Styles>
                  <Header ImageSpacing="5px" SortingImageSpacing="5px">
                  </Header>
                  <Row>
                    <Border BorderColor="#006666" BorderStyle="Solid" BorderWidth="1px" />
                  </Row>
                </Styles>
                <SettingsPager Mode="ShowAllRecords">
                </SettingsPager>
                <ClientSideEvents EndCallback="function(s,e){ongvFile_EndCallback(s,e);}" />
                <Settings ShowColumnHeaders="False"></Settings>
                <StylesEditors>
                  <ProgressBar Height="25px">
                  </ProgressBar>
                </StylesEditors>
              </dxwgv:ASPxGridView>
            </div>
        </td>
      </tr>
    </table>
    <div style="padding-top: 5px;">
      <dxhe:ASPxHtmlEditor ClientVisible="true" ID="htmlEditor" ClientInstanceName="htmlEditor"
        runat="server" Width="100%" ActiveView="Design">
        <SettingsImageUpload>
          <ValidationSettings AllowedContentTypes="image/jpeg,image/pjpeg,image/gif,image/png,image/x-png">
          </ValidationSettings>
        </SettingsImageUpload>
        <Images>
          <DialogFormCloseButton Height="17px" Width="17px" />
        </Images>
        <Styles>
          <ViewArea>
            <Border BorderColor="#4986A2" BorderStyle="Solid" BorderWidth="1px" />
          </ViewArea>
        </Styles>
        <PartsRoundPanel>
          <TopLeftCorner Height="5px" Width="5px" />
          <NoHeaderTopLeftCorner Height="5px" Width="5px" />
          <TopRightCorner Height="5px" Width="5px" />
          <NoHeaderTopRightCorner Height="5px" Width="5px" />
          <BottomRightCorner Height="5px" Width="5px" />
          <BottomLeftCorner Height="5px" Width="5px" />
          <HeaderLeftEdge>
            <BackgroundImage Repeat="RepeatX" VerticalPosition="bottom" />
          </HeaderLeftEdge>
          <HeaderContent>
            <BackgroundImage Repeat="RepeatX" VerticalPosition="bottom" />
          </HeaderContent>
          <HeaderRightEdge>
            <BackgroundImage VerticalPosition="bottom" />
          </HeaderRightEdge>
          <NoHeaderTopEdge BackColor="#EBF2F4">
          </NoHeaderTopEdge>
          <RightEdge>
            <BackgroundImage Repeat="RepeatX" VerticalPosition="bottom" />
          </RightEdge>
          <BottomEdge BackColor="#D7E9F1">
          </BottomEdge>
          <LeftEdge>
            <BackgroundImage Repeat="RepeatX" VerticalPosition="bottom" />
          </LeftEdge>
          <Content>
            <BackgroundImage Repeat="RepeatX" VerticalPosition="bottom" />
          </Content>
        </PartsRoundPanel>
        <StylesRoundPanel>
          <ControlStyle BackColor="#EBF2F4">
            <Border BorderColor="#7EACB1" BorderStyle="Solid" BorderWidth="1px" />
          </ControlStyle>
        </StylesRoundPanel>
        <StylesToolbars>
          <Toolbar ItemSpacing="0px" SeparatorHeight="100%">
          </Toolbar>
        </StylesToolbars>
        <StylesStatusBar>
          <Tab>
            <Paddings PaddingBottom="5px" PaddingTop="4px" />
          </Tab>
          <ActiveTab>
            <Paddings PaddingBottom="5px" PaddingTop="4px" />
          </ActiveTab>
          <StatusBar TabSpacing="0px">
          </StatusBar>
        </StylesStatusBar>
      </dxhe:ASPxHtmlEditor>
    </div>
    <div style="padding-top: 10px; float: left;">
      <dxe:ASPxButton ID="btnSend" ClientInstanceName="btnSend" runat="server" Text="<%$ Resources:Strings, Send %>">
        <ClientSideEvents Click="function(s,e){sendMail();e.processOnServer=false;}" />
      </dxe:ASPxButton>
    </div>
    <div style="padding-top: 10px; float: left; padding-left: 3px;">
      <dxe:ASPxButton ID="ASPxButton3" ClientInstanceName="btnSend" runat="server" Text="<%$ Resources:Strings, Close %>">
        <ClientSideEvents Click="function(s,e){GoBack();e.processOnServer=false;}" />
      </dxe:ASPxButton>
    </div>
  </div>
  <div>
    <dxcb:ASPxCallback ID="ctrlCallback" ClientInstanceName="ctrlCallback" runat="server"
      OnCallback="ctrlCallback_Callback">
      <ClientSideEvents CallbackComplete="function(s,e){onctrlCallback_CallbackComplete(s,e);}" />
    </dxcb:ASPxCallback>
    <asp:HiddenField ID="hfEmailType" runat="server" />
  </div>

  <script type="text/javascript" language="javascript">
    function GoBack() {
      var url = window.location.href;
      index = url.indexOf("CustomerContactDetail.aspx?t=") + 29;
      var type = url.substring(index, index + 1);
      window.location.href = 'CustomerContact.aspx?t=' + type;

    }
    function showFlash(show) {
      var flash = document.getElementById('swfu_container');
      if (show)
        flash.style.display = 'block';
      else
        flash.style.display = 'none';
    }

    function setEmailType(type) {
      document.getElementById('<%=hfEmailType.ClientID %>').value = type;
    }

    function ongvList_EndCallback(s, e) {
      var error = gvList.cpInnerError;
      if (error != '')
        alertMessage(error);
    }

    function showCompose(show) {
      var frmEmail = document.getElementById('frmEmailList');
      var frmCompose = document.getElementById('frmCompose');
      if (show) {
        resetValue();
        frmEmail.style.display = 'none';
        frmCompose.style.display = 'block';
        htmlEditor.SetVisible(true);
        showFlash(show);
      }
      else {
        frmEmail.style.display = 'block';
        frmCompose.style.display = 'none';
        htmlEditor.SetVisible(false);
      }
    }

    function onTabChange(s, e) {
      var tabName = e.tab.name;
      if (tabName == "Compose") {
        resetValue();
        showCompose(true);
      }
      else
        showCompose(false);
    }

    function showEmailList() {
      //resetValue();
      gvSelect.PerformCallback('Load');
    }

    function ongvSelect_EndCallback(s, e) {
      gvSelect.SelectAllRowsOnPage(false);
      showFlash(false);
      pcEmailList.Show();
    }

    function resetValue() {
      gvSelect.SelectAllRowsOnPage(false);
      cbxTo.SetValue('');
      cbxCC.SetValue('');
      cbxBCC.SetValue('');
      txtSubject.SetText('');
      htmlEditor.SetHtml('');

      //Remove all attchment
      for (var i = 0; i < gvFile.GetVisibleRowsOnPage(); i++) {
        gvFile.DeleteRow(i);
      }
      gvFile.SetVisible(false);
    }

    function ongvFile_EndCallback(s, e) {
      if (s.GetVisibleRowsOnPage() > 0)
        s.SetVisible(true);
      else
        s.SetVisible(false);
    }

    function attachFile() {
      gvFile.PerformCallback('Save|');
    }

    function onSelect() {
      gvSelect.GetSelectedFieldValues('Email', onGetSelectedEmail);
    }

    function onGetSelectedEmail(selectedValues) {
      var emailList = '';
      for (var i = 0; i < selectedValues.length; i++) {
        emailList += selectedValues[i] + ';';
      }
      var type = document.getElementById('<%=hfEmailType.ClientID %>').value;
      switch (type) {
        case 'TO':
          cbxTo.SetText(cbxTo.GetText() + emailList);
          break;
        case 'CC':
          cbxCC.SetText(cbxCC.GetText() + emailList);
          break;
        case 'BCC':
          cbxBCC.SetText(cbxBCC.GetText() + emailList);
          break;
      }
      pcEmailList.Hide();
      showFlash(true);
    }

    function onCancel() {
      pcEmailList.Hide();
      showFlash(true);
    }

    function sendMail() {
      //if (checkSendMailInput()) {
      pcWaiting.Show();
      ctrlCallback.SendCallback();
      // }
    }

    function onctrlCallback_CallbackComplete(s, e) {
      pcWaiting.Hide();
      if (e.result != '') {
        alertMessage(e.result);
        return;
      }
      // resetValue();
      // alertMessage('<%=(string)GetGlobalResourceObject("Messages", "ERR0033") %>');
      GoBack();
    }

    function onFileSelect() {
      if (uploader.GetText() == '')
        return;
      document.getElementById('frmUpload').style.display = 'none';

    }

    function checkSendMailInput() {
      var error = '';
      if (cbxTo.GetText() == '') {
        error += '<BR> + <%=(string)GetGlobalResourceObject("Strings","To") %>';
        error = '<%=(string)GetGlobalResourceObject("Messages", "ERR0008") %>' + error;
      }

      if (error != '') {
        alertMessage(error);
        return false;
      }

      error = '<%=(string)GetGlobalResourceObject("Messages","ERR0031") %>';
      if (!validateEmailList(cbxTo.GetText())) {
        alertMessage(error);
        return false;
      }

      if (!validateEmailList(cbxCC.GetText())) {
        alertMessage(error);
        return false;
      }

      if (!validateEmailList(cbxBCC.GetText())) {
        alertMessage(error);
        return false;
      }

      return true;
    }

    function validateEmailList(emailString) {
      var emailList = emailString.split(';');
      var isValid = true;
      if (emailList != null)
        for (var i = 0; i < emailList.length; i++) {
        if (emailList[i] == '')
          continue;
        if (!ValidateEmail(emailList[i])) {
          isValid = false;
          break;
        }
      }
      return isValid;
    }
  </script>

</asp:Content>
